package com.sxt.sys.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * 把简单的集合转化为标准json对象的集合
 * 
 * @author LJH
 * 
 */
public class TreeNodeBuilder {

	/**
	 * 
	 * @param treeNodes
	 * @param topRootPid
	 */
	public static List<TreeNode> builder(List<TreeNode> treeNodes,
			Integer topRootPid) {
		List<TreeNode> nodes = new ArrayList<>();
		for (TreeNode n1 : treeNodes) {
			if (n1.getPid() == topRootPid) {
				nodes.add(n1);
			}
			for (TreeNode n2 : treeNodes) {
				if (n1.getId() == n2.getPid()) {// 说明n2是n1的子节点
					n1.getChildren().add(n2);
				}
			}

		}
		return nodes;
	}

}
